﻿using System;
using System.Collections.Generic;
using System.Text;
using UtilZ.Dotnet.Ex.Base;

namespace UtilZ.Dotnet.Ex.Model
{
    /// <summary>
    /// 序列化器基类
    /// </summary>
    public class DefaultXmlSerializer : ISerializer
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public DefaultXmlSerializer()
        {

        }




        /// <summary>
        /// 将当前对象序列化为目标类型的对象
        /// </summary>
        /// <param name="obj">要序列化的对象</param>
        /// <returns>序列化后的数据</returns>
        public object Serialize(object obj)
        {
            return SerializeEx.XmlSerializer(obj);
        }

        /// <summary>
        /// 将目标类型的对象反序列化到当前对象
        /// </summary>
        /// <param name="serializeData">序列化数据</param>
        /// <returns>反序列化后的对象</returns>
        public T Deserialize<T>(object serializeData) where T : new()
        {
            string xml = (string)serializeData;
            return SerializeEx.XmlDeserializerFromString<T>(xml);
        }

        /// <summary>
        /// 将序列化数据反序列化到目标类型的对象
        /// </summary>
        /// <param name="serializeData">序列化数据</param>
        /// <param name="targetType">目标类型</param>
        /// <returns>反序列化后的对象</returns>
        public object Deserialize(object serializeData, Type targetType)
        {
            string xml = (string)serializeData;
            return SerializeEx.XmlDeserializerFromString(xml, targetType);
        }

        /// <summary>
        /// 将序列化数据反序列化到目标类型的对象
        /// </summary>
        /// <param name="targetObj">目标对象</param>
        /// <param name="serializeData">序列化数据</param>
        public void Deserialize(object targetObj, object serializeData)
        {
            throw new NotImplementedException();
        }

    }
}
